package apies;

import java.net.MalformedURLException;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ExecutionException;

import org.apache.http.message.BasicNameValuePair;

import android.util.Log;

public class VkApi {
	private static final String BASE_URL = "https://api.vk.com/method/";
	private static final String SECRET = "EpHAOvDzWqN6Ofn8oJxh";
	private static final String API_ID = "3995007";
	
	private String _token;
	private String _id;
	
	public VkApi(String access_token, String id) {
		setAccessToken(access_token);
		_id = id;
	}
	
	public void setAccessToken(String token) {
		_token = token;
	}
	
	public String getUsers() {
		String method = "users.get";
		String result = "";
		
		List<BasicNameValuePair> pairs = new ArrayList<BasicNameValuePair>();
		pairs.add(new BasicNameValuePair("uids", _id));
		pairs.add(new BasicNameValuePair("fields", "sex, bdate, city, contry, photo_100, photo_max_orig"));
		pairs.add(new BasicNameValuePair("access_token", _token));
		
		try {
			Connection conn = new Connection(BASE_URL+method, pairs);
			result = conn.execute((Void)null).get();
		} catch (MalformedURLException e) {
			Log.d("api", e.toString());
			e.printStackTrace();
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (ExecutionException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return result;
	}
	
	public String getCities(String cityId) {
		String method = "getCities";
		String result = "";
		List<BasicNameValuePair> pairs = new ArrayList<BasicNameValuePair>();
		pairs.add(new BasicNameValuePair("api_id", API_ID));
		pairs.add(new BasicNameValuePair("cids", cityId));
		try {
			Connection conn = new Connection(BASE_URL+method,  pairs);
			result = conn.execute((Void)null).get();
		} catch (MalformedURLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (ExecutionException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return result;
	}
	

}
